home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / NDK / NDK_1.3 / Read-Me1.3 / Printer1.3 / Driver.Examples / src / xerox_4020 / dospecial.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-01  |  4.7 KB  |  230 lines

  1. /*
  2.     DoSpecial for Xerox_4020 driver.
  3.     David Berezowski - March/88.
  4. */
  5.  
  6. #include "exec/types.h"
  7. #include "../printer/printer.h"
  8. #include "../printer/prtbase.h"
  9.  
  10. #define PITCH        4
  11. #define    QUALITY        9
  12. #define INITLEN        16
  13.  
  14. #define TABLEN        34
  15.  
  16. #define PITCHMARG    2
  17. #define LMARG        5
  18. #define RMARG        11
  19. #define MARGLEN        15
  20. /*
  21.     00-02    \033F0        - assure correct pitch        PMARG
  22.     03-08    \033l000\015    - set left margin to '000'    LMARG
  23.     09-14    \033r000\015    - set right margin to '000'    RMARG
  24. */
  25. UBYTE MargBuf[MARGLEN] = "\033F0\033l000\015\033r000\015";
  26. UBYTE pitch;
  27.  
  28. DoSpecial(command, outputBuffer, vline, currentVMI, crlfFlag, Parms)
  29. char outputBuffer[];
  30. UWORD *command;
  31. BYTE *vline;
  32. UBYTE *currentVMI; /* used for color on this printer */
  33. BYTE *crlfFlag;
  34. UBYTE Parms[];
  35. {
  36.     extern struct PrinterData *PD;
  37.  
  38.     int x = 0, y= 0;
  39.     static BYTE ISOcolorTable[10] =
  40.         {49, 51, 53, 52, 55, 50, 54, 48, 49, 49};
  41.     /*       K   R   G   Y   B   M   C   W   K   K */
  42.  
  43.     /*
  44.         00-01    \033R    - underline off
  45.         02-04    \033F0    - 10 cpi            PITCH
  46.         05-06    \033&    - enlarge off
  47.         07-09    \033wb    - nlq off            QUALITY
  48.         10-11    \033s    - super/sub script off
  49.         12-14    \033we    - standard graphics mode
  50.         15-15    \015    - carriage return
  51.     */
  52.     static char initThisPrinter[INITLEN] =
  53.         "\033R\033F0\033&\033wb\033s\033we\015";
  54.     static unsigned char initTabs[TABLEN] =
  55.         "\033i9 17 25 33 41 49 57 65 73 81 89\015";
  56.  
  57.     if (*command == aRIN) {
  58.         while(x < INITLEN) {
  59.             outputBuffer[x] = initThisPrinter[x];
  60.             x++;
  61.         }
  62.         while (y < TABLEN) {
  63.             outputBuffer[x++] = initTabs[y++];
  64.         }
  65.         y = 0;
  66.  
  67.         *currentVMI = 0x70; /* white background, black text */
  68.  
  69.         if (PD->pd_Preferences.PrintQuality == LETTER) {
  70.             outputBuffer[QUALITY] = 'a';
  71.         }
  72.  
  73.         if (PD->pd_Preferences.PrintPitch == PICA) {
  74.             pitch = 10;
  75.             outputBuffer[PITCH] = '0';
  76.         }
  77.         else if (PD->pd_Preferences.PrintPitch == ELITE) {
  78.             pitch = 12;
  79.             outputBuffer[PITCH] = '2';
  80.         }
  81.         else { /* FINE */
  82.             pitch = 17;
  83.             outputBuffer[PITCH] = '4';
  84.         }
  85.  
  86.         Parms[0] = PD->pd_Preferences.PrintLeftMargin;
  87.         Parms[1] = PD->pd_Preferences.PrintRightMargin;
  88.         *command = aSLRM;
  89.     }
  90.  
  91.     if (*command == aCAM) {
  92.         Parms[0] = 1;
  93.         Parms[1] = (95 * 17 + 5) / 10; /* max is 9.5 inches @ 17 cpi */
  94.         *command = aSLRM;
  95.     }
  96.  
  97.     if (*command == aSLRM) {
  98.         CalcMarg(Parms[0], Parms[1]);
  99.         while (y < MARGLEN) {
  100.             outputBuffer[x++] = MargBuf[y++];
  101.         }
  102.         return(x);
  103.     }
  104.  
  105.     /* normal pitch, or elite off, or condensed off, or normal char set */
  106.     if (*command == aSHORP0 || *command == aSHORP1 || *command == aSHORP3
  107.         || *command == aSGR0) {
  108.         pitch = 10;
  109.     }
  110.     else if (*command == aSHORP2) { /* elite on */
  111.         pitch = 12;
  112.     }
  113.     else if (*command == aSHORP4) { /* fine on */
  114.         pitch = 17;
  115.     }
  116.  
  117.     if (*command == aSFC) { /* set foreground/background color */
  118.         if (Parms[0] == 39) {
  119.             Parms[0] = 30; /* set defaults */
  120.         }
  121.         if (Parms[0] == 49) {
  122.             Parms[0] = 47;
  123.         }
  124.         if (Parms[0] < 40) {
  125.             *currentVMI = (*currentVMI & 240) + (Parms[0] - 30);
  126.         }
  127.         else {
  128.             *currentVMI = (*currentVMI & 15) + (Parms[0] - 40) *
  129.                 16;
  130.         }
  131.         outputBuffer[x++] = '\033';
  132.         outputBuffer[x++] = '@';
  133.         outputBuffer[x++] = ISOcolorTable[*currentVMI & 15];
  134.         outputBuffer[x++] = ISOcolorTable[(*currentVMI & 240) / 16];
  135.         return(x);
  136.     }
  137.  
  138.     if (*command == aPLU) {
  139.         if (*vline == 0) {
  140.             *vline = 1;
  141.             *command = aSUS2;
  142.             return(0);
  143.         }
  144.         if (*vline < 0) {
  145.             *vline = 0;
  146.             *command = aSUS3;
  147.             return(0);
  148.         }
  149.         return(-1);
  150.     }
  151.  
  152.     if (*command == aPLD) {
  153.         if (*vline == 0) {
  154.             *vline = -1;
  155.             *command = aSUS4;
  156.             return(0);
  157.         }
  158.         if (*vline > 0) {
  159.             *vline = 0;
  160.             *command = aSUS1;
  161.             return(0);
  162.         }
  163.         return(-1);
  164.     }
  165.  
  166.     if (*command == aSUS0) {
  167.         *vline = 0;
  168.     }
  169.     if (*command == aSUS1) {
  170.         *vline = 0;
  171.     }
  172.     if (*command == aSUS2) {
  173.         *vline = 1;
  174.     }
  175.     if (*command == aSUS3) {
  176.         *vline = 0;
  177.     }
  178.     if (*command == aSUS4) {
  179.         *vline = -1;
  180.     }
  181.  
  182.     if (*command == aRIS) {
  183.         PD->pd_PWaitEnabled = 253;
  184.         pitch = 10;
  185.     }
  186.  
  187.     return(0);
  188. }
  189.  
  190. CalcMarg(left, right)
  191. int left, right;
  192. {
  193.     int i, j, offset, max;
  194.  
  195.     /*
  196.         The minimum left margin on the Xerox_4020 is .5 inches.  Thus
  197.         a left margin of 1 (ie. no left margin) is ...
  198.         5/10 => .5, 6/12 => .5, 8.5/17 => .5
  199.         The maximum print width is 9.5 inches.
  200.     */
  201.     if (pitch == 10) { /* PICA */
  202.         MargBuf[PITCHMARG] = '0';
  203.         offset = 40;
  204.         max = (95 * 10 + 5) / 10;
  205.     }
  206.     else if (pitch == 12) { /* ELITE */
  207.         MargBuf[PITCHMARG] = '2';
  208.         offset = 50;
  209.         max = (95 * 12 + 5) / 10;
  210.     }
  211.     else { /* FINE */
  212.         MargBuf[PITCHMARG] = '4';
  213.         offset = 75;
  214.         max = (95 * 17 + 5) / 10;
  215.     }
  216.     if ((i = (left * 10 + offset + 5) / 10) > max) {
  217.         i = max;
  218.     }
  219.     MargBuf[LMARG] = ((i % 1000) / 100) + '0';
  220.     MargBuf[LMARG + 1] = ((i % 100) / 10) + '0';
  221.     MargBuf[LMARG + 2] = (i % 10) + '0';
  222.     if ((i = (right * 10 + offset + 15) / 10) > max) {
  223.         i = max;
  224.     }
  225.     MargBuf[RMARG] = ((i % 1000) / 100) + '0';
  226.     MargBuf[RMARG + 1] = ((i % 100) / 10) + '0';
  227.     MargBuf[RMARG + 2] = (i % 10) + '0';
  228.     return(MARGLEN);
  229. }
  230.